package day05;

import java.util.ArrayList;
import java.util.Random;

public class homework_master {
    private String name;
    private int money;

    public homework_master(int money, String name) {
        this.name = name;
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }
    public void show(){

        System.out.println(this.getName()+"的钱还有"+this.getMoney());
    }

    public ArrayList<Integer> sendmoney(int total, int count) {
        ArrayList<Integer> redlist = new ArrayList<>();
        Random random = new Random();
        if (total > this.getMoney()) {
            System.out.println("余额不足");
            return redlist;
        }
        this.setMoney(this.getMoney()-total);
        int num;
        for (int i = 0; i < count-1; i++) {
            num = random.nextInt((total / (count-i))*2);
            if (num==0&&total!=0){
                num = random.nextInt((total /(count-i))*2);
                redlist.add(num);
                total = total - num;
            }
            redlist.add(num);
            total = total - num;
        }
        redlist.add(total);
        return redlist;
    }
}
